package entity

import (
	"strconv"
	"database/sql"
)

type DormitoryInfo struct {
	DormitoryId     int    `json:"dormitoryId"`
	DormitoryUuid   string `json:"dormitoryUuid"`
	DormitoryName   string `json:"dormitoryName"`
	Owner           string `json:"owner"`
	Members         string `json:"members"`
	MembersRealName string `json:"membersRealName"`
	MemberNum       int    `json:"memberNum"`
	Address         string `json:"address"`
	CreateTime      int64  `json:"createTime"`
}

func (dormitoryInfo DormitoryInfo) String() string {
	return "(" + " DormitoryId = " + strconv.Itoa(dormitoryInfo.DormitoryId) + "," + " DormitoryUuid = " + dormitoryInfo.DormitoryUuid + "," + " DormitoryName = " + dormitoryInfo.DormitoryName + "," + " Owner = " + dormitoryInfo.Owner + "," + " Members = " + dormitoryInfo.Members + "," + " MembersRealName = " + dormitoryInfo.MembersRealName + "," + " MemberNum = " + strconv.Itoa(dormitoryInfo.MemberNum) + "," + " Address = " + dormitoryInfo.Address + "," + " CreateTime = " + strconv.FormatInt(dormitoryInfo.CreateTime, 10) + " )";
}

func ReadDormitoryInfoData(rows *sql.Rows) []DormitoryInfo {
	var dormitoryInfotSlice []DormitoryInfo = make([]DormitoryInfo, 0)
	for rows.Next() {
		dormitoryInfo := new(DormitoryInfo)
		err := rows.Scan(&dormitoryInfo.DormitoryId, &dormitoryInfo.DormitoryUuid, &dormitoryInfo.DormitoryName, &dormitoryInfo.Owner, &dormitoryInfo.Members,&dormitoryInfo.MemberNum, &dormitoryInfo.MembersRealName,  &dormitoryInfo.Address, &dormitoryInfo.CreateTime)
		if err != nil {
			panic(err)
		}
		dormitoryInfotSlice = append(dormitoryInfotSlice, *dormitoryInfo)
	}
	return dormitoryInfotSlice
}
